<template>
  <a-card>
    <div>
      <standard-table
        :columns="columns"
        :dataSource="pageData.records"
        :rowKey="(record,index)=>{return index}"
        :pagination="false"
      >
        <div slot="description" slot-scope="{ text }">
          {{ text }}
        </div>
        <div slot="action" slot-scope="{record}">
          <router-link style="margin-right: 8px" :to="`/device/device/edit/${record.id}`" ><a-icon type="edit" />编辑</router-link>
          <router-link style="margin-right: 8px" :to="`/device/device/detail/${record.id}`" >详情</router-link>
        </div>
        <template slot="statusTitle">
          <a-icon @click.native="onStatusTitleClick" type="info-circle" />
        </template>
      </standard-table>
    </div>
  </a-card>
</template>

<script>
import StandardTable from '@/components/table/StandardTable'
import {devicePage} from '@/services/device'

const columns = [
  {
    title: 'ID',
    dataIndex: 'id'
  },
  {
    title: '设备名',
    dataIndex: 'deviceName'
  },
  {
    title: '展示图片',
    dataIndex: 'imgUrl',
    render(val) {
        return <img src={ val ? val : ''} style={{width: 100}} />;
      }
  },
  {
    title: '所属产品',
    dataIndex: 'product.productName',
  },
  {
    title: 'IP地址',
    dataIndex: 'ipAddr',
  },
  {
    title: '创建时间',
    dataIndex: 'gmtCreate'
  },
  {
    title: '更新时间',
    dataIndex: 'gmtModified'
  },
  {
    title: '操作',
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'QueryList',
  components: {StandardTable},
  data () {
    return {
      advanced: true,
      columns: columns,
      pageData: {current:1, limit: 15, total: 0},
    }
  },
  mounted() {
    this.queryDevicePage()
  },
  methods: {
    queryDevicePage() {
      devicePage({}).then((rep)=>{
        this.pageData = rep.data.data
        this.dataSource = rep.data.data.records
      })
    },
    deleteRecord(key) {
      this.dataSource = this.dataSource.filter(item => item.key !== key)
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    remove () {
      this.dataSource = this.dataSource.filter(item => this.selectedRows.findIndex(row => row.key === item.key) === -1)
    },
    onStatusTitleClick() {
      this.$message.info('你点击了状态栏表头')
    },
    onChange() {
      this.$message.info('表格状态改变了')
    },
    addNew () {
      this.dataSource.unshift({
      })
    },
    handleMenuClick (e) {
      if (e.key === 'delete') {
        this.remove()
      }
    }
  }
}
</script>

<style lang="less" scoped>
.search {
  margin-bottom: 54px;
}
.fold {
  width: calc(100% - 216px);
  display: inline-block;
}
.operator {
  margin-bottom: 18px;
}
@media screen and (max-width: 900px) {
  .fold {
    width: 100%;
  }
}
</style>
